﻿<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>VIP企业管理</title>
<meta http-equiv="Cache-Control" content="no-cache" />
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="./css/x-admin.css" media="all">
<link rel="stylesheet" href="./css/backstage.css" media="all">
<script src="js/line.js"></script>
<script src="./js/jquery.min.js"></script>
<link rel="stylesheet" href="./js/layui/css/layui.css" media="all">
<script src="./js/layui/layui.all.js"></script>

<script>   	
		//日期控件
		$(function(){
		  layui.use('laydate', function(){
			 var laydate = layui.laydate;
			 laydate.render({elem: '#searchbegin'});
			 laydate.render({elem: '#searchend'});
		 }); 
		});
		

		var sortType="ASC";  //用于控制升或降序,特意做成全局变量
		
        $(function(){     	
        	 search();
        });
        
        function search(){
        	var comName= $("#comName").val();
        	var management= $("#management").val();
        	var searchbegin= $("#searchbegin").val();
        	var searchend= $("#searchend").val();
        	var pageIndex=1;  //当前是第几页,默认是第一页       	
        	renderData(pageIndex,comName,management,searchbegin,searchend);
        }
             
        function renderData(pageIndex,comName,management,searchbegin,searchend){
        	$("tbody").empty();

        	$.ajax({
        		url:"../admin/vipcomlist",
        		data:{comName:comName,management:management,searchbegin:searchbegin,searchend:searchend,page:pageIndex,limit:15,sortType:sortType},
        		dataType:"json",
        		async:false,
        		success:function(result){
        			var vipList=result.obj.list;
        			for(var i=0;i<vipList.length;i++){
        				var v=vipList[i];
 				
        				var tr="";
        	        	tr+="<tr>";
        	        	tr+="<td >"+v.registerTime+"</td>";
        	        	tr+="<td >"+v.vipend+"</td>";
        	        	tr+="<td><a title='"+v.comName+"'  href='vipInformation.html?comid="+v.comid+"'> "+v.shortComName+"</a></td>";
        	        	tr+="<td ><span class='demo'>"+"<a style='text-decoration:none' title='"+v.management+"'>"+ v.shortManagement+"</a>"+"</span></td>" ;
        	        	tr+="<td class='td-manage'>";
        	        	tr+="<a class='mlbtn' href='javascript:void(0)'  onclick=update("+v.comid+")>修改</a>";
        	        	tr+="<a class='mlbtn' href='javascript:void(0)'  onclick=del("+v.comid+")>删除</a>";  
        	        	tr+="</td>";
        	        	tr+="</tr>";

        	        	$("#tbody").append(tr);	
        			}
        			
        			pageFun(result.obj,comName,management,searchbegin,searchend);
        		}
        	});
        }
        
        
        function update(comid){
        	window.location.href="newvip.html?comid="+comid;
        }
        
        function del(comid){
        	if(confirm("确定要删除吗?")==true){
       		  $.ajax({
					url:"../admin/deleteVipCompany",
					data:{comid:comid},
					success:function(data){
						alert("删除成功!");
						search();
					}
				});
        	}
        }
	
        </script>
        
        <script>
        
       	   //分页函数
	    	function pageFun(data,comName,management,searchbegin,searchend){
	    		pageinfo="";
	    		//总页数
	         	pagenums=parseInt(data.pages);
	    		//当前页
	         	pagecurrent=parseInt(data.pageNum); 
	    		//可视页数
	    		showpages=15;
	    		
	         	if(pagecurrent>1){
	         		pageinfo+="<li><a href='javascript:void(0);' onclick=\"renderData("+(pagecurrent-1)+",'"+comName+"','"+management+"','"+searchbegin+"','"+searchend+"')\"> < </a></li>";
	         	}else{
	         		pageinfo+="<li><a href='javascript:void(0);'> < </a></li>";
	         	}     	
	         	for_begin=1;
	         	for_judge=1;
	         	pageinf_begin="";
	         	pageinf_end="";
	         	if(pagenums>0){
	    	     	if(pagenums<=showpages){ 
	    	     		for_begin=1;
	    	     		for_judge=pagenums;
	    	     		pageinf_begin="";
	    	     		pageinf_end="";
	    	     	}
	    	     	else if(pagenums>showpages && pagecurrent==1){
	         		  for_begin=1;
	    	     	  for_judge=showpages;
	    	     	  pageinf_begin="";
	    	     	  pageinf_end="<li><a>...</a></li>";     		   
	         	   }
	    	     	else if(pagenums<=(pagecurrent+showpages) && pagecurrent>1){
	         		  for_begin=pagecurrent;
	    	     	  for_judge=pagenums;
	    	     	  pageinf_begin="<li><a>...</a></li>";
	    	     	  pageinf_end="";
	         	   }
	    	     	else if(pagenums>(pagecurrent+showpages) && pagecurrent>1){
	         		  for_begin=pagecurrent;
	    	     	  for_judge=pagecurrent+showpages-1;
	    	     	  pageinf_begin="<li><a>...</a></li>";
	    	     	  pageinf_end="<li><a>...</a></li>";
	         	   }
	         	   
	         	  pageinfo+=pageinf_begin; 
	         	  for(i=for_begin;i<=for_judge;i++){
	       			if(i==pagecurrent){
						pageinfo+="<li  class='active'><a href='javascript:void(0);' onclick=\"renderData("+i+",'"+comName+"','"+management+"','"+ searchbegin+"','" + searchend+"')\">"+i+"</a></li>";
	       			}else{
	       				pageinfo+="<li><a href='javascript:void(0);' onclick=\"renderData("+i+",'"+comName+"','"+management+"','"+ searchbegin+"','" + searchend+"')\">"+i+"</a></li>";
	       			}
	       	      }  
	         	  pageinfo+=pageinf_end;
	         	
	         	 if(pagecurrent<pagenums){
	         		pageinfo+="<li><a href=\"javascript:renderData("+(pagecurrent+1)+",'"+comName+"','"+management+"','"+ searchbegin+"','"+  searchend+"')\"> > </a></li>";
	         	 }else{
	         		pageinfo+="<li><a href='javascript:void(0);'> > </a></li>";
	         	 } 
	             $(".pagelist ul").empty();
	         	 $(".pagelist ul").append( pageinfo );
	         	 }
	    	}
   
       	   
       	   //上传vip申请模板
       	  function uploadDoc(){
       		  $.ajax({
         		   url : "../admin/uploadVipDoc",
         		   data: new FormData($("#form-doc")[0]),
         		   type : "POST",
         		   // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
         		   processData : false,
         		   // 告诉jQuery不要去设置Content-Type请求头
         		   contentType : false,
         		 
         		   success : function(data) {
         		   	 alert(data.message);
         		   }
         	  });
       	  }
       	   
       	   //重新排序查询
       	   function resort(){
       		   if(sortType=="ASC"){
      			   $("#img_sort").attr("src","images/down.png");
      			   sortType="DESC"; 
      			   search();
      			  
       		   }
       		   else{
	       		  $("#img_sort").attr("src","images/up.png");
	       		  sortType="ASC";
	       		  search();
	       		 
       		   }
       	   }
 
        </script>
</head>
<body>
<div class="wrap">
	<form id="form-doc" enctype="multipart/form-data">
	  <input style="display:none" type="file" id="vipdoc" name="vipdoc" onchange="uploadDoc()" >
	</form>
	<div class="x-nav">
		<div class="title">
			<a><cite>VIP企业管理</cite></a> 
			<a href="newvip.html">新增VIP企业</a>
			<a href="javascript:void(0)" onclick="$('#vipdoc').click()">上传VIP申请书模板</a>
		</div>

	</div>
	<div class="form">
			<p><span>检索区:</span></p> 
			<p><span>按企业名称</span> <input type="text" id="comName"/> </p> 
			<p><span>按主营项目</span> <input type="text" id="management"/> </p> 
			<p><span>按入驻日期</span> <input   id="searchbegin" placeholder="开始日期"/> </p> 
			<p><span>到</span> <input   id="searchend" placeholder="截止日期"/></p> 
			<p><button class="btn2" onclick="search()">
				<i class="layui-icon">&#xe615;</i> 搜索
			</button></p> 
	</div>
	  	      
	<div class="x-body">
            <table  class="layui-table" id="table">
                <thead>
                    <tr>
                        <th>入驻日期</th>
                        <th>VIP到期 &nbsp; <img id="img_sort" onclick="resort()" src="images/up.png"> </th>
                        <th>企业全称</th>
                        <th>主营项目</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody id="tbody">
                </tbody>
            </table>

	        <div class="pagelist">
	            <ul class="nav">
	            </ul>
	        </div>     
	</div>
</div>

</body>
</html>